/**********************************************************************************************
 UIBevelButton
 Copyright (C) <2012> <John W. Buchanan>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
 Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************************************/

#import "UIBevelButton.h"

@implementation UIBevelButton

-(void) setupButton
{
	[super setupButton];
	float edgesize = 8;
	int i;
	
	self.layer.cornerRadius = m_CornerRadius/2;
	self.layer.masksToBounds = YES;
    self.layer.borderColor = [[UIColor blackColor]CGColor];
	self.layer.borderWidth = 0.8f;
    i=0;
    GradientHolder *grad = [[GradientHolder alloc] initWithFrame:self.frame];
    [grad setRelative:NO];
    
	
    [grad setXOffset:0.0f];
    [grad setYOffset:0.0f];
    [grad setHeight:edgesize];
    [grad setWidth:0.0f]; // Make full width;
    
    
	[grad setNormalColors: [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5f]CGColor],
							[(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
	[grad setSelectedColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							 [(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
    
    [m_Gradients addObject:grad];
    
	i += 1;
	
	grad = [[GradientHolder alloc] initWithFrame:self.frame];
    [grad setRelative:NO];
    [grad setHeight:edgesize];
	[grad setWidth:0.0f];
	[grad setYOffset:-edgesize];
	[grad setNormalColors: [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							[(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
	[grad setSelectedColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							 [(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5f]CGColor ],nil]];
    
    [m_Gradients addObject:grad];
   	
    i += 1;
    grad = [[GradientHolder alloc] initWithFrame:self.frame];
    [grad setRelative:NO];
    [grad setXOffset:-edgesize];
	[grad setWidth:edgesize];
	[grad setHeight:0.0];
	[grad setNormalColors: [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							[(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5f]CGColor ],nil]];
	[grad setSelectedColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							 [(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
    [grad setVertical:NO];
	[m_Gradients addObject:grad]; 
	
    i += 1;
    grad = [[GradientHolder alloc] initWithFrame:self.frame];
    [grad setRelative:NO];
    [grad setXOffset:0];
	[grad setWidth:edgesize];
	[grad setHeight:0.0f];
	
	[grad setNormalColors: [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor],
							[(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
	[grad setSelectedColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5f]CGColor],
							 [(id)[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0f]CGColor ],nil]];
    [grad setVertical:NO];
	
    [m_Gradients addObject:grad]; 
	
	
	
    for ( i = 0; i< [m_Gradients count]; i += 1) 
    {
        grad = [m_Gradients  objectAtIndex:i];
        [self.layer insertSublayer:grad.layer atIndex:i];
		[grad makeNormal];
    }
    
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self != nil) 
	{
        [self setupButton];
    }
    return self;
}

- (void)awakeFromNib 
{
	[super awakeFromNib];
	[self setupButton];

}


@end
